<template>
  <div class="app-container">
<el-input
          placeholder="输入关键字进行过滤"
          v-model="filterText"
        ></el-input>
    <el-tree
      class="filter-tree"
      :data="data"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree"
    >
    </el-tree>
  </div>
</template>

<script>
import subject from "@/api/edu/subject";

export default {
  data() {
    return {
      data: [],
      filterText: "",
      listLoading: false,
      defaultProps: {
        children: "children",
        label: "label",
      },
      importUrl: process.env.VUE_APP_BASE_API + "/service_edu/subject/import",
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      subject.getAll().then((res) => {
        this.data = res.data.result;
        this.listLoading = false;
      });
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.label.toLowerCase().indexOf(value.toLowerCase()) !== -1;
    },
  },
};
</script>
